package com.yiwei.zhh.util;


import com.yiwei.zhh.constant.Const;

/**
 * AES加密/解密 密钥
 * Created by Master.Dong on 2016/4/11.
 */
public class KeyHandler {

    private String key = "";

    private boolean defaultKey = true;

    private static KeyHandler instance;

    public static synchronized KeyHandler getInstance(){
        if(instance == null){
            instance = new KeyHandler();
        }
        return instance;
    }

    /**
     * 获取加密密钥，需要优化
     * @return
     */
    public String getKey(){
        if("".equals(key) || Const.DEFAULT_KEY.equals(key)){
            key = Const.DEFAULT_KEY;
            defaultKey = true;
        }else{
            defaultKey = false;
        }
        return key;
    }

    public void setKey(String key){
        this.key = key;
    }

    public boolean isDefaultKey() {
        return defaultKey;
    }

    public void setDefaultKey(boolean defaultKey) {
        this.defaultKey = defaultKey;
    }

}
